package com.hxzy.projectssmplus.controller;

import com.hxzy.projectssmplus.dto.LoginDTO;
import com.hxzy.projectssmplus.entity.SysAdminUser;
import com.hxzy.projectssmplus.service.SysAdminUserService;
import com.hxzy.projectssmplus.util.ThreadLocalUtils;
import com.hxzy.projectssmplus.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 登录
 */
@RestController
public class LoginController extends BaseController{

    @Autowired
    private SysAdminUserService sysAdminUserService;

    @PostMapping(value = "/user/login")
    public AjaxResult login(@Valid @RequestBody LoginDTO loginDTO){
        return this.sysAdminUserService.login(loginDTO);
    }




    /**
     * 取得当前用户信息
     * @return
     */
    @GetMapping(value = "/user/info")
    public AjaxResult getInfo(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return AjaxResult.success_data(authentication);
    }
}
